﻿using System;
using CDOP.Model;

namespace CDOP.UserControls
{
    public partial class UcProcessingofDeath : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void AddObjectValues(ref MasterTable recordToFill)
        {
            recordToFill.Mode_of_Death = ddModeofDeath.SelectedItem.Text;
            recordToFill.Reported_Coroner = ddReportedCoroner.SelectedItem.Text;
            recordToFill.Inquest = ddInquest.SelectedItem.Text;
            if (txtInquestDate.Text != string.Empty)
                recordToFill.Inquest_Date = Convert.ToDateTime(txtInquestDate.Text).ToShortDateString();
            recordToFill.Inquest_Complete = ddInquestComplete.SelectedItem.Text;
            recordToFill.Inquest_Verdict = ddInquestVerdict.SelectedItem.Text;
            recordToFill.Reported_Registra = ddReportedRegistra.SelectedItem.Text;
            recordToFill.Post_Mortem = ddPostMortem.SelectedItem.Text;
            recordToFill.Medical_Certificate_Cause_of_Death_Issued =
                ddMedicalCertificateCauseofDeathIssued.SelectedItem.Text;
            recordToFill.Registered_Cause_of_Death_1 = txtRegisteredCauseofDeath01.Text;
            recordToFill.Registered_Cause_of_Death_2 = txtRegisteredCauseofDeath02.Text;
            recordToFill.Registered_Cause_of_Death_3 = txtRegisteredCauseofDeath03.Text;
            recordToFill.Registered_Cause_of_Death_4 = txtRegisteredCauseofDeath04.Text;
            if (txtMothersDob.Text != string.Empty)
                recordToFill.Mothers_DOB = Convert.ToDateTime(txtMothersDob.Text).ToShortDateString();
            recordToFill.Recommendations = txtRecommendations.Text;
        }

        public void LoadObjectValues(ref MasterTable recordToFill)
        {
            if (ddModeofDeath.Items.Count == 0)
                ddModeofDeath.DataBind();
            ddModeofDeath.SelectedIndex = ddModeofDeath.Items.IndexOf(ddModeofDeath.Items.FindByText(recordToFill.Mode_of_Death));
            if (ddReportedCoroner.Items.Count == 0)
                ddReportedCoroner.DataBind();
            ddReportedCoroner.SelectedIndex = ddReportedCoroner.Items.IndexOf(ddReportedCoroner.Items.FindByText(recordToFill.Reported_Coroner));
            if (ddInquest.Items.Count == 0)
                ddInquest.DataBind();
            ddInquest.SelectedIndex = ddInquest.Items.IndexOf(ddInquest.Items.FindByText(recordToFill.Inquest));
            if (recordToFill.Inquest_Date != null)
                txtInquestDate.Text = recordToFill.Inquest_Date.ToString();
            if (ddInquestComplete.Items.Count == 0)
                ddInquestComplete.DataBind();
            ddInquestComplete.SelectedIndex = ddInquestComplete.Items.IndexOf(ddInquestComplete.Items.FindByText(recordToFill.Inquest_Complete));
            if (ddInquestVerdict.Items.Count == 0)
                ddInquestVerdict.DataBind();
            ddInquestVerdict.SelectedIndex = ddInquestVerdict.Items.IndexOf(ddInquestVerdict.Items.FindByText(recordToFill.Inquest_Verdict));
            if (ddReportedRegistra.Items.Count == 0)
                ddReportedRegistra.DataBind();
            ddReportedRegistra.SelectedIndex = ddReportedRegistra.Items.IndexOf(ddReportedRegistra.Items.FindByText(recordToFill.Reported_Registra));
            if (ddPostMortem.Items.Count == 0)
                ddPostMortem.DataBind();
            ddPostMortem.SelectedIndex = ddPostMortem.Items.IndexOf(ddPostMortem.Items.FindByText(recordToFill.Post_Mortem));
            if (ddMedicalCertificateCauseofDeathIssued.Items.Count == 0)
                ddMedicalCertificateCauseofDeathIssued.DataBind();
            ddMedicalCertificateCauseofDeathIssued.SelectedIndex = ddMedicalCertificateCauseofDeathIssued.Items.IndexOf(ddMedicalCertificateCauseofDeathIssued.Items.FindByText(recordToFill.Medical_Certificate_Cause_of_Death_Issued));
            txtRegisteredCauseofDeath01.Text = recordToFill.Registered_Cause_of_Death_1;
            txtRegisteredCauseofDeath02.Text = recordToFill.Registered_Cause_of_Death_2;
            txtRegisteredCauseofDeath03.Text = recordToFill.Registered_Cause_of_Death_3;
            txtRegisteredCauseofDeath04.Text = recordToFill.Registered_Cause_of_Death_4;
            if (recordToFill.Mothers_DOB != null)
                txtMothersDob.Text = recordToFill.Mothers_DOB.ToString();
            txtRecommendations.Text = recordToFill.Recommendations;
        }

        //#region Date Fill Events

        //protected void LnkBtnInquestDateClick(object sender, EventArgs e)
        //{
        //    calInquestDate.Visible = true;
        //}

        //protected void CalInquestDateOnSelectionChanged(object sender, EventArgs e)
        //{
        //    txtInquestDate.Text = calInquestDate.SelectedDate.Date.ToString();
        //    calInquestDate.Visible = false;
        //}

        //protected void LnkBtnMothersDobClick(object sender, EventArgs e)
        //{
        //    calMothersDob.Visible = true;
        //}

        //protected void CalMothersDobOnSelectionChanged(object sender, EventArgs e)
        //{
        //    txtMothersDob.Text = calMothersDob.SelectedDate.Date.ToString();
        //    calMothersDob.Visible = false;
        //}

        //#endregion

    }
}